/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipServiceFood;
import com.sasis.dao.VipServiceFoodDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipServiceFoodDaoiBatis extends BaseDaoiBATIS implements VipServiceFoodDao {

    /**
     * @see com.sasis.dao.VipServiceFoodDao#getVipServiceFoods(com.sasis.model.VipServiceFood)
     */
    public List getVipServiceFoods(final VipServiceFood vipServiceFood) {
          return getSqlMapClientTemplate().queryForList("getVipServiceFoods", vipServiceFood);
    }

    /**
     * @see com.sasis.dao.VipServiceFoodDao#getVipServiceFood(Integer id)
     */
    public VipServiceFood getVipServiceFood(Integer id) {
        VipServiceFood vipServiceFood = (VipServiceFood) getSqlMapClientTemplate().queryForObject("getVipServiceFood", id);

//        if (vipServiceFood == null) {
//            throw new ObjectRetrievalFailureException(VipServiceFood.class, id);
//        }

        return vipServiceFood;
    }

    /**
     * @see com.sasis.dao.VipServiceFoodDao#saveVipServiceFood(VipServiceFood vipServiceFood)
     */    
    public int saveVipServiceFood(final VipServiceFood vipServiceFood) {
        Integer id = vipServiceFood.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipServiceFood", vipServiceFood);
        } else {
            getSqlMapClientTemplate().update("updateVipServiceFood", vipServiceFood);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipServiceFood.class, id);
        }
        
        return id.intValue(); 
    }

    /**
     * @see com.sasis.dao.VipServiceFoodDao#removeVipServiceFood(Integer id)
     */
    public void removeVipServiceFood(VipServiceFood vipServiceFood) {
        getSqlMapClientTemplate().update("deleteVipServiceFood",  vipServiceFood);
    }
}
